const {
  getClassifyPajamas,
  getGoods,
  getList
} = require("../../http/api")
Page({
  data: {
    classifyTitle: [],
    goodsList: [],
    active: 0,
  },
  onLoad: function (option) {
    // console.log(option.id);
    
    // this.setData({
    //   active: Number(option.index),
    // });


    getList().then((res) => { //请求商品
      console.log(res);
      this.setData({
        goodsList: res,
      });
    });

  },
  onShow() { //请求商品
    getClassifyPajamas().then((res) => { //请求商品名称
      console.log(res);
      this.setData({
        classifyTitle: res,
      })
    })
  },
  onClicktab(e) { //点击切换;
    // console.log(e);
    this.setData({
      goodsList: "",
    });
    var {
      id
    } = e.currentTarget.dataset.item;

    getGoods(id).then((res) => { //请求商品
      this.setData({
        goodsList: res,
      });
    })

    let {
      index
    } = e.currentTarget.dataset;
    // console.log(index);
    this.index = this.active
    this.setData({
      active: index,
    });
  },
  onClickDtail(e) { //分类详情
    console.log(e);
    let goodsId = e.currentTarget.dataset.cateid.id;
    // console.log(goodsId);

    wx.navigateTo({
      url: '/pages/commodity/commodity?id=' + goodsId,
    })
  },
  //搜索
  search(value) {
    console.log(value);
    let detail = value.detail.value;
    console.log(detail);
    
    wx.navigateTo({
        url: '/pages/Searchpage/Searchpage?placeId=' + detail + '',
      }),
      wx.showLoading({
        title: '跳转中...',
      })

    setTimeout(function () {
      wx.hideLoading()
    }, 500)
  },

})